package com.xxwy.lintcode;

/**
 * @author xxwy
 * on 2018/10/10 0010
 * decode ways
 */
public class Num512 {
    public static int numDecodings(String string) {
        // write your code here
        char[] s = string.toCharArray();
        int n = s.length;
        if (n == 0) {
            return 0;
        }
        int[] f = new int[n + 1];
        f[0] = 1;
        int i;
        for (i = 1; i <= n; i++) {
            f[i] = 0;
            int t = s[i - 1] - '0';
            if (t > 0 && t <= 9) {
                f[i] += f[i-1];
            }
            if (i >= 2) {
                int t2 =( s[i - 2] - '0' )* 10 + (s[i - 1]- '0');
                if(t2>=10 && t2<=26) {
                    f[i] += f[i-2];
                }
            }
        }
        return f[n];
    }

    public static void main(String[] args) {
        Num512.numDecodings("12");
    }
}
